import Tabbar from "vux/src/components/tabbar/tabbar.vue";
import TabbarItem from "vux/src/components/tabbar/tabbar-item.vue";

import { removeClass, addClass } from "@/assets/js/dom.js";

import template from "./footerTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  components: {
    Tabbar,
    TabbarItem,
  },
  data() {
    return {
      notLoginFlag: false,
      isActive: 0,
    };
  },
  created() {},
  methods: {
    goRouter(index, path) {
      this.isActive = index;
      this.$router.push(path);
    },
    goToWallet() {
      this.isActive = 1;
      if (!localStorage.getItem("token")) {
        this.notLoginFlag = true;
        return false;
      } else {
        this.$router.push({
          path: "/wallet",
        });
      }
    },
    goToServer() {
      this.isActive = 2;
      if (!localStorage.getItem("token")) {
        this.notLoginFlag = true;
        return false;
      } else {
        this.$router.push({
          path: '/moneyTransform'// "/server",
        });
      }
    },
    goToEvent() {
      this.isActive = 4;
      if (!localStorage.getItem("token")) {
        this.notLoginFlag = true;
        return false;
      } else {
        this.$router.push({
          path: '/activityCenter'
        });
      }
    },
    goToPersonalCenter() {
      this.isActive = 3;
      if (!localStorage.getItem("token")) {
        this.notLoginFlag = true;
        return false;
      } else {
        this.$router.push({
          path: "/personalCenter",
        });
      }
    },
    onConfirm() {
      this.$router.push({
        path: "/login",
      });
    },
  },
  watch: {
    $route: {
      handler() {
        this.$nextTick(() => {
          let path = this.$route.path;
          let footer = document.querySelector("#footer");
          if (footer && footer.querySelector(".weui-bar__item_on")) {
            removeClass(
              footer.querySelector(".weui-bar__item_on"),
              "weui-bar__item_on"
            );
          }
          switch (path) {
            case "/":
              this.isActive = 0;
              break;
            case "/wallet":
              this.isActive = 1;
              break;
            case "/server":
              this.isActive = 2;
              break;
            case "/personalCenter":
              this.isActive = 3;
              break;
            default:
              break;
          }
        });
      },
      immediate: true,
    },
  },
};

// WEBPACK FOOTER //
// ./src/components/common/footer.vue
